package com.iot.ht.controller.htmenu;

import com.iot.core.annotation.Auth;
import com.iot.core.annotation.Log;
import com.iot.core.data.BaseQto;
import com.iot.core.data.TreeViewNode;
import com.iot.core.enums.AuthType;
import com.iot.core.manager.auth.AuthManager;
import com.iot.ht.controller.htmenu.data.HtMenuDto;
import com.iot.ht.controller.htmenu.data.HtMenuInsertQto;
import com.iot.ht.controller.htmenu.service.IHtMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/htmenu")
@Tag(name = "菜单管理", description = "")
public class HtMenuController {
    @Autowired
    IHtMenuService ihtMenuService;

    @Auth(authType = AuthType.Login)
    @Log(logNeed = false,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/insertinit")
    @Operation(summary = "插入菜单初始化", description = "")
    public HtMenuDto insertInit(@RequestBody HtMenuInsertQto mm )   {
         return  ihtMenuService.insertInit(mm);
    }


    @Auth(authType = AuthType.Login)
    @Log(logNeed = false,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/detail")
    @Operation(summary = "菜单详情", description = "")
    public HtMenuDto detail(@RequestBody BaseQto mm){
        return ihtMenuService.detail(mm);
    }

    @Auth(authType = AuthType.Auth)
    @Log(logNeed = true,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/insert")
    @Operation(summary = "新增菜单", description = "")
    public  int insert(@RequestBody HtMenuDto mm){
        return ihtMenuService.insert(mm);
    }


    @Auth(authType = AuthType.Auth)
    @Log(logNeed = true,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/update")
    @Operation(summary = "修改菜单", description = "")
    public  int update(@RequestBody HtMenuDto mm){
        return ihtMenuService.update(mm);
    }


    @Auth(authType = AuthType.Auth)
    @Log(logNeed = true,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/delete")
    @Operation(summary = "删除菜单", description = "")
    public  int delete(@RequestBody BaseQto mm){
        return ihtMenuService.delete(mm);
    }


    @Auth(authType = AuthType.Login)
    @Log(logNeed = false,logTemplete ="",logPin = true,logPout = true)
    @PostMapping("/gettree")
    @Operation(summary = "功能菜单分页", description = "")
    public List<TreeViewNode> getTree(@RequestBody BaseQto mm){
        return AuthManager.getInstance().getMenuByHtplatId(mm.getId() );
    }





}
